package controllers;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.HtmlEmail;

import play.mvc.Controller;

import com.sun.org.apache.bcel.internal.generic.NEW;


public class MailsendtaskAction extends Controller{
	
	/** 封装邮件发送 */
	public static void sendMail(String to, String title,
			String content) {
		int state = 0 ;
		try {
			System.out.println(content);
			

			// 创建邮件信息
			HtmlEmail email = new HtmlEmail();
			email.setCharset("utf-8");
			email.setTLS(true);
			email.setHostName("smtp.qq.com");
			email.setFrom("1650495908@qq.com", "蓝莲花有限公司");
			email.setAuthentication("1650495908@qq.com", "123456789");	
			email.addTo(to);
			
			System.out.println(content);
			email.setSubject(title.trim());
			// StringBuffer html = new StringBuffer();
			// html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
			// html.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
			// html.append("<head>");
			// html.append("<base href=\""+basepath+"/\" />");
			// html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gbk\" />");
			// html.append("</head>");
			// html.append("<body>"+Tools.unescape(content.trim())+"</body></html>");
			email.setHtmlMsg(content.trim());
			// email.setHtmlMsg(Tools.unescape(content.trim()));
			// 发送邮件
			email.send();
			state = 1;
			render(state);
		} catch (Exception ex) {
			state = 0 ;
			render(state);
			ex.printStackTrace();
		}
	}
}



